package com.vhall.component.service.pendant.listener;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.vhall.component.dao.pendant.PendantStatsMapper;
import com.vhall.component.entity.pendant.PendantStatsEntity;
import com.vhall.component.service.pendant.event.PendantClickReportEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

/**
 * 挂件上报监听事件
 *
 * @author shimingming
 * @since 2023/8/11 11:11
 */
@Service
@Slf4j
@EnableAsync
public class PendantClickReportEventListener implements ApplicationListener<PendantClickReportEvent> {

    @Autowired
    private PendantStatsMapper pendantStatsMapper;

    /**
     * 异步处理 挂件上报
     */
    @Async
    @Override
    public void onApplicationEvent(PendantClickReportEvent event) {

        LambdaUpdateWrapper<PendantStatsEntity> wrapper = event.getUpdateWrapper();
        pendantStatsMapper.update(null, wrapper);

    }
}